<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>售后列表</title>
</head>
<style>
    .table>tbody>tr>td{
        text-align:center;
    }
</style>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 订单管理 <span class="c-gray en">&gt;</span> 售后列表 <a id="btn-refresh" class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <form id="form-search" class="text-c">
        <select class="select-box" style="width: 100px" id="status">
            <option value="">状态</option>
            <option value="0">待处理</option>
            <option value="1">已处理</option>
            <option value="2">已拒绝</option>
        </select>
        <select class="select-box" style="width: 100px" id="type">
            <option value="">售后类型</option>
            <option value="0">只退款</option>
            <option value="1">退款退货</option>
            <option value="2">更换</option>
        </select>
        <input type="text" class="input-text" style="width:250px" placeholder="输入订单编号或用户名" id="searchKey" name="searchKey">
        <button id="searchButton" type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
    </form>
    <div class="mt-20" style="margin-bottom: 70px">
        <table class="table table-border table-bordered table-hover table-bg table-sort" width="100%">
            <thead>
            <tr class="text-c">
                <th width="80">订单编号</th>
                <th width="80">用户名</th>
                <th width="40">类型</th>
                <th width="110">申请理由</th>
                <th width="80">退款支付宝</th>
                <th width="100">图片</th>
                <th width="80">提交时间</th>
                <th width="40">状态</th>
                <th width="110">操作</th>
            </tr>
            </thead>
        </table>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="lib/datatables/dataTables.colReorder.min.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="lib/common.js"></script>
<script type="text/javascript">

    $(document).on('click','td img', function(){
        var src = $(this).attr('src');
        layer.open({
            type: 1,
            title: '',
            content: '<image src="'+ src +'"  style="max-width:300px;"/>'
        });
    });

    $(function() {
        $('.table').dataTable({
            serverSide: true,//开启服务器模式
            "processing": true,//加载显示提示
            "ajax": {
                url:"orderReturnExchange/list",
                type: 'GET',
                data:{
                    "searchKey": ""
                }
            },
            "createdRow": function( row, data, dataIndex ) {
                $(row).children('td').eq(3).css({
                    'overflow':'hidden',
                    'white-space':'nowrap',
                    'max-width':'150px',
                    'text-overflow': 'ellipsis',
                    'text-align': 'left',
                    'cursor': 'pointer'
                });
                $(row).children('td').eq(3).attr('title', data.reason);
            },
            "columns": [
                { "data": "orderId"},
                { "data": "memberName"},
                { "data": "type",
                    render: function (data, type, row, meta) {
                        if(data == 0) return '只退款';
                        if(data == 1) return '退款退货';
                        if(data == 2) return '换货';
                        return '未知类型';
                    }
                },
                { "data": "reason"},
                { "data": "alipayAccount"},
                {
                    "data": "image",
                    render: function (data, type, row, meta) {
                        var html = '';
                        if(data){
                            var images = data.split(",");
                            for(var i=0; i<images.length; i++){
                                html += '<img src="' + images[i] + '" title="点击查看大图" style="cursor: pointer;max-height: 20px;margin-right:10px;" alt="" />'
                            }
                        }
                        return html;
                    }
                },
                { "data": "created",
                    render : function(data,type, row, meta) {
                        return date(data);
                    }
                },
                { "data": "status",
                    render: function (data, type, row, meta) {
                        if(data == 0) return '<span class="label label-defant radius td-status">待处理</span>';
                        if(data == 1) return '<span class="label label-success radius td-status">已处理</span>';
                        if(data == 2) return '<span class="label label-danger radius td-status">已拒绝</span>';
                        return '未知状态';
                    }
                },
                { "data": null,
                    render : function(data,type, row, meta) {
                        if(row.status == 0){
                            var html = '';
                            html += '<a title="处理" href="javascript:;" class="ml-5" onclick="deal('+ row.id +')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6a7;</i></a>&nbsp;&nbsp;';
                            html += '<a title="拒绝" href="javascript:;" class="ml-5" onclick="refuse('+ row.id +')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6a6;</i></a>';
                            return html;
                        }
                        return '-';
                    }
                }
            ],
            "aaSorting": [[ 6, "desc" ]],//默认第几个排序
            "bStateSave": false,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {"orderable":false,"aTargets":[3,5,8]}// 制定列不参与排序
            ],
            language: {
                url: '/lib/datatables/Chinese.json'
            },
            colReorder: true
        });

    });


    function deal(id){
        layer.confirm('确认要将该售后申请设置为已处理？',{icon:0},function(index){
            var index = layer.load(3);
            $.ajax({
                type: 'POST',
                url: '/orderReturnExchange/deal/'+id,
                dataType: 'json',
                success: function(data){
                    layer.close(index);
                    if(data.success!=true){
                        layer.alert(data.message,{title: '错误信息',icon: 2});
                        return;
                    }
                    refresh();
                    layer.msg('处理成功!',{icon:1,time:1000});
                },
                error:function(XMLHttpRequest){
                    layer.close(index);
                    layer.alert('数据处理失败! 错误码:'+XMLHttpRequest.status,{title: '错误信息',icon: 2});
                }
            });
        });
    }

    function refuse(id){
        layer.confirm('确认要将该售后申请设置为已拒绝？',{icon:0},function(index){
            var index = layer.load(3);
            $.ajax({
                type: 'POST',
                url: '/orderReturnExchange/refuse/'+id,
                dataType: 'json',
                success: function(data){
                    layer.close(index);
                    if(data.success!=true){
                        layer.alert(data.message,{title: '错误信息',icon: 2});
                        return;
                    }
                    refresh();
                    layer.msg('拒绝成功!',{icon:1,time:1000});
                },
                error:function(XMLHttpRequest){
                    layer.close(index);
                    layer.alert('数据处理失败! 错误码:'+XMLHttpRequest.status,{title: '错误信息',icon: 2});
                }
            });
        });
    }

    /*多条件查询*/
    $("#form-search").validate({
        rules:{
            type:{
                required:false
            },
            status:{
                required:false
            },
            searchKey:{
                required:false
            }
        },
        onkeyup:false,
        focusCleanup:false,
        success:"valid",
        submitHandler:function(form){
            var searchKey= $('#searchKey').val();
            var type= $('#type').val();
            var status= $('#status').val();
            var param = {
                "searchKey": searchKey,
                "status": status,
                "type":type
            };
            var table = $('.table').DataTable();
            table.settings()[0].ajax.data = param;
            table.ajax.reload();
        }
    });
</script>
</body>
</html>
